<template>
  <el-form :model="form" label-width="80px">
    <el-form-item label="用户名">
      <el-input v-model="form.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="form.password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">登录</el-button>
    </el-form-item>
  </el-form>
</template>
 
<script>
import { useStore } from '@/stores';
import { useRouter } from 'vue-router';
 
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    };
  },
  setup() {
    const store = useStore();
    const router = useRouter();
 
    const onSubmit = () => {
      // 这里应该调用后端API进行登录验证
      store.login({ username: this.form.username });
      router.push('/');
    };
 
    return {
      form,
      onSubmit
    };
  }
};
</script>

